package jjn.round2;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Jiang Jining
 * @since 2023-06-13 23:37
 */
public class LeetCode2475_UnequalTriples {
    public int unequalTriplets(int[] nums) {
        Map<Integer, Integer> count = new HashMap<>();
        for (int num : nums) {
            count.put(num, count.getOrDefault(num, 0) + 1);
        }
        if (count.size() < 3) {
            return 0;
        }
        int res = 0, n = nums.length, t = 0;
        for (Map.Entry<Integer, Integer> entry : count.entrySet()) {
            res += t * entry.getValue() * (n - t - entry.getValue());
            t += entry.getValue();
        }
        return res;
    }
}
